<?php
class Paging extends CI_Controller {
	
	private static $results_per_page = 15;
	private $terms = array (); // default empty search terms array
	

	/**
	 *
	 * Here goes your function description
	 *
	 */
	function __construct() {
		
		parent::__construct ();
		$this->results_per_page = self::$results_per_page;
		$this->load->model ( 'Paging_model' );
		$this->load->helper ( 'form' );
	
//		$this->output->enable_profiler(TRUE);
	}
	
	/**
	 *
	 * Here goes your function description
	 *
	 */
	function index() {
		
		$this->search ();
	
	}
	
	/**
	 *
	 * Here goes your function description
	 *
	 */
	function search() {
		
		foreach ( $_POST as $key => $value ) {
			echo $key . " " . "=" . " " . $value;
			echo "<BR>";
		}
		if (! isset ( $_POST ['submit'] )) {
			
			// reset the search terms
			$this->session->unset_userdata ( 's_key_one' );
			$this->session->unset_userdata ( 's_key_two' );
			$this->session->unset_userdata ( 's_key_three' );
			
			// application_search is our view that contains the form
			$this->load->view ( 'application_view' );
			print_r ( 'aaaaaaaa' );
		} else {
			print_r ( 'bbbbbbbbb' );
			//			// this is how it works if you store your validation rules in a file
			//			// if you do, good, if not, make sure that you have a file that contains your
			//			// validation rules in a format that can be found in CI's user guide
			//			$this->config->load('form_validation', TRUE);
			//			$this->form_validation->set_rules($this->config->item('application', 'form_validation'));
			// 
			//			if ($this->form_validation->run('application') == FALSE){
			// 
			//				$this->load->view('application_search');
			// 
			//			}
			//			else {
			

			$this->terms ['s_key_one'] = $this->input->post ( 'key_one' );
			$this->terms ['s_key_two'] = $this->input->post ( 'key_two' );
			$this->terms ['s_key_three'] = $this->input->post ( 'key_three' );
			
			$this->session->set_userdata ( $this->terms );
			
			redirect ( 'paging/view' );
		
		//			}
		

		}
	
	}
	
	/**
	 *
	 * Here goes your function description
	 *
	 */
	function view() {
		
		$this->load->library ( 'pagination' );
		
		$offset = $this->uri->segment ( 3, 0 );
		$total = $this->Paging_model->count_all ();
		$data ['results'] = $this->Paging_model->get_all ( $this->results_per_page, $offset );
		
		$data ['total_rows'] = $total;
		
		$config ['base_url'] = base_url () . 'index.php/paging/view';
		$config ['total_rows'] = $total;
		$config ['per_page'] = $this->results_per_page;
		$config ['uri_segment'] = 3;
		$config ['num_links'] = 3;
		
		$this->pagination->initialize ( $config );
		
		$data ['page_links'] = $this->pagination->create_links ();
		
		$data ['key_one'] = $this->session->userdata ( 'key_one' );
		$data ['offset'] = $offset;
		print_r ( $this->db->last_query () );
		// application_view is our results page
		

		$this->load->view ( 'application_view', $data );
	
	}

}
 
/* End of file application.php */
/* Location: ./system/application/controllers/application.php */